import React from 'react';
// import lookforward from '@/assets/lookforward.png';
import { BottomAction } from '@/components';
import { Button, Form, message, Popconfirm, Empty } from 'antd';
import pageTabUtil from '@/utils/pageTabUtil';
import { useRequest, defaultFormatResult } from '@/hooks';
import { history } from 'umi'
import { getSystemTodoList, completeHandover } from '../../service';
import styles from './index.less';
import { CollapseHeader, LimitInput, WorkHandoverTable } from '../components';

import { LEAVE_STATUS_OBJ } from '../../dictionary';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function WorkHandover(props) {
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const { form, dimissionOrderId, data, employeeCode, ...rest } = props;
    const [submitLoading, setSubmitLoading] = React.useState();
    const { getFieldDecorator, validateFields } = form;

    const params = {
        pageNo: 1,
        pageSize: 10000,
        taskStatus: '0'
    };
    // employeeCode: oa1145573189141659650
    const { data: systemTododata, loading: systemTodoloading } = useRequest(
        () => getSystemTodoList(params, employeeCode),
        { ...defaultFormatResult }
    );
    const handleSubmit = () => {
        const { matterDetail } = data;
        const handlerDetail = matterDetail?.find(m => m.handoverType === LEAVE_STATUS_OBJ.WORK_HANDOVER);
        if (!handlerDetail) {
            message.error('未查询到工作交接详情');
            return;
        }
        validateFields(async (err, values) => {
            if (err) {
                return;
            }
            try {
                setSubmitLoading(true);
                const { code, msg } = await completeHandover({
                    id: handlerDetail?.id,
                    dimissionOrderId,
                    handoverType: LEAVE_STATUS_OBJ.WORK_HANDOVER,
                    ...values
                });
                if (code === 10000) {
                    message.success('提交成功！');
                    history.replace('/office/personnelManagement/onboardAndLeave/leaveManagement/list');
                } else {
                    message.error(msg);
                }
                setSubmitLoading(false);
            } catch (e) {
                setSubmitLoading(false);
            }
        });
    };
    return (
        <>
            <CollapseHeader title="工作任务">
                <div style={{ margin: '40px 0px 60px' }}>
                    <Empty description="开发中，敬请期待" />
                </div>
            </CollapseHeader>
            <CollapseHeader title="系统待办">
                <div className={styles.itemBox}>请督促离职人员，完成以下系统待办事项：</div>
                <WorkHandoverTable systemTododata={systemTododata} loading={systemTodoloading} />
            </CollapseHeader>
            <CollapseHeader title="绩效评定">
                <div style={{ margin: '40px 0px 60px' }}>
                    <Empty description="开发中，敬请期待" />
                </div>
            </CollapseHeader>
            <CollapseHeader title="备注" style={{ width: 500 }}>
                {getFieldDecorator('remark', {
                    initialValue: data.matterDetail[0].remark
                })(<LimitInput area autoSize={{ minRows: 3, maxRows: 6 }} placeholder="请填写备注" maxLength={4000} />)}
            </CollapseHeader>
            <BottomAction>
                <Button onClick={() => pageTabUtil.goBack()}>取消</Button>
                {systemTododata?.total === 0 ? (
                    <Button type="primary" onClick={handleSubmit} loading={submitLoading}>
                        确定
                    </Button>
                ) : (
                    <Popconfirm
                        title={
                            <>
                                离职人员的系统代办未完成，
                                <br />
                                确定交接完成？
                            </>
                        }
                        placement="bottomRight"
                        onConfirm={handleSubmit}
                        okText="确定"
                        cancelText="取消"
                    >
                        <Button type="primary" style={{ marginRight: 8 }}>
                            确定
                        </Button>
                    </Popconfirm>
                )}
            </BottomAction>
        </>
    );
}
export default Form.create()(WorkHandover);
